class UpdateShader{
    constructor(){
        this.originFrag = null;
    }
    update(tile,fs){
        let content = tile.content;
        for (let i = 0; i < content.featuresLength; i++) {
          let feature = content.getFeature(i);
          let model = feature.content._model;
          if (this._properties && this._properties.length) {
            this._properties.forEach((property) => {
              if (
                feature.hasProperty(property["key"]) &&
                feature.getProperty(property["key"]) === property["keyValue"]
              ) {
                feature.setProperty(
                  property["propertyName"],
                  property["propertyValue"]
                );
              }
            });
          }
          if (
            fs &&
            model &&
            model._sourcePrograms &&
            model._rendererResources
          ) {
            Object.keys(model._sourcePrograms).forEach((key) => {
              let program = model._sourcePrograms[key];
              
              if (this.originFrag == null) {
                this.originFrag = model._rendererResources.sourceShaders[
                  program.fragmentShader
                ];
              }
              //如果传入的参数是origin，则把默认数据赋给originFrag
              //TODO: 目前不确定切换模型后是否会报错！！若报错，可能要设定数组来存储样式
              if (fs == 'origin') {
                model._rendererResources.sourceShaders[
                  program.fragmentShader
                ] = this.originFrag ;
              }
              else{
                model._rendererResources.sourceShaders[
                  program.fragmentShader
                ] = fs;
              }
            });
            model._shouldRegenerateShaders = true;
          }
        }
    }
}
export default new UpdateShader();